#pragma once
#include <vector>
#include <cstdio>
#include <cstdint>

using namespace std;

//读取第N张图片，从0开始
vector<double> read_image(int n)
{
    uint8_t temp;
    vector<double> ret;
    FILE *fp = fopen("./train_set/train-images.idx3-ubyte", "rb");

    ret.resize(785);
    fseek(fp, 0, SEEK_SET);
    fseek(fp, (n * 784 + 16), SEEK_SET);

    ret[784] = 1;
    for (int i = 0; i < 784; i++)
    {
        fread(&temp, 1, 1, fp);
        ret[i] = ((double)temp) / 255; //(double)(temp * 0.003921569);
    }
    fclose(fp);
    return ret;
}

//读取第N张图片对应标签，从0开始
vector<double> read_label(int n)
{
    uint8_t temp = 0;
    vector<double> ret;
    FILE *fp = fopen("./train_set/train-labels.idx1-ubyte", "rb");

    ret.resize(10);
    fseek(fp, (8 + n), SEEK_SET);
    fread(&temp, 1, 1, fp);
    ret[temp] = 1;

    fclose(fp);
    return ret;
}
